const app = getApp();

module.exports = (url, data, method = "get", header = {}) => {
   // loading动画 数据加载之前
   var _loading = false

   if (!_loading) {
      wx.showLoading({
         title: "Loading...",
         mask: true
      })
      _loading = true
   }



   // 二次封装接口
   return new Promise((resolve, reject) => {
      wx.request({
         url: app.globalData.url + url,
         data,
         method, // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
         header, // 设置请求的 header
         success: resolve,
         fail: reject,
         complete: function () {
            if (_loading) {
               wx.hideLoading()
            }
            _loading = false
         }


      })
   })


}